function y=bigxinew(xivals,alphbar,acost,bcost,scriptB)
%
% Compute the expected adjustment cost
%
% Input
% 1. xivals: the specific cost
% 2. alphbar: the proportion of firms receiving zero cost
% 3. acost: a parameter for the Beta/Dotsey dist.
% 4. bcost: a parameter for the Beta/Dotsey dist.
% 5. scriptB: the largest fixed cost
%


xivals=min(xivals,scriptB);
xivals=max(xivals,0); 


%% BETA distribution

% % converted support for Beta dist.
% z = xivals/scriptB;
% 
% % the truncated mean
% mean = betainc(z,acost+1,bcost);
% mean = mean.*(acost/(acost+bcost));
% 
% out = ((1-alphbar)*scriptB).*mean;

%%


%% DOTSEY distribution

z=xivals/scriptB;

minp=min([acost bcost]);
maxp=max([acost bcost]);

if (minp<=-pi/2)||(bcost>=pi/2)
    disp('inadmissable parameter values for dotsey distribution')
    disp('in call to xcidf.m')
end

K1=1/(tan(bcost)-tan(acost));
K2=-tan(acost)*K1;

x=z*bcost+(1-z)*acost;
ratio=K1/(bcost-acost);

y=z.*(K1*tan(x));
y=y+ratio*(log(abs(cos(x)))-log(cos(acost)));

% multiply by scale of adjustment costs
y=scriptB*y;

% modify underlying distribution to produce adjusted distribution
y=(1-alphbar)*y;


%%

end

